/**
 * Created by tdzl2003 on 8/12/16.
 */
import {loadUserInfo} from '../logics/auth';
import {loadToken} from '../logics/rpc';

export default {
  path: '/',
  onEnter: (location, replace, callback) => {
    if (!loadToken()) {
      return callback();
    }
    loadUserInfo().then(()=>callback(), ()=>callback());
  },
  getComponent: (nextState, callback) => {
    require.ensure([], function (require) {
      callback(null, require('./Site').default);
    });
  },
  indexRoute: {
    onEnter: (location, replace) => {
      replace('/home');
    },
  },
  childRoutes: [
    {
      path: 'home',
      getComponent: (nextState, callback) => {
        require.ensure([], function (require) {
          callback(null, require('./Home').default);
        });
      }
    },
    require('./user').default,
    require('./game').default,
    require('./gift').default,
    require('./drawout').default,
    require('./example').default,
    require('./acc').default,
  ],
};
